package com.zzl.bonds.ticket.constant.status;

import com.zzl.bonds.ticket.dto.KeyValue;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 授信状态枚举值
 *
 * @author : spp
 * @date : 2022/3/1 14:04
 */
public enum CreditStatusEnum {

    /**
     * 全部
     */
    ALL(0, "全部", ""),
    NOT_EFFECTIVE(1, "未生效", ""),
    SUCCESS(2, "生效", ""),
    FAIL(3, "已失效", ""),
    FROZEN(4, "冻结", "");

    private Integer code;
    private String name;
    private String description;

    public static List<Integer> NOT_AVAILABLE_LIST = Arrays.asList(1, 3, 4);

    CreditStatusEnum(Integer code, String name, String description) {
        this.code = code;
        this.name = name;
        this.description = description;
    }

    /**
     * 业务类型
     *
     * @return 枚举值对象
     */
    public static List<KeyValue> getKvList() {
        List<KeyValue> keyValues = new ArrayList<>();
        for (CreditStatusEnum statusEnum : CreditStatusEnum.values()) {
            KeyValue kv = new KeyValue();
            kv.setKey(statusEnum.code);
            kv.setValue(statusEnum.name);
            keyValues.add(kv);
        }
        return keyValues;
    }

    /**
     * 通过code获取枚举对象
     *
     * @param code code值
     * @return 枚举对象
     */
    public static String getStatusName(Integer code) {
        for (CreditStatusEnum value : CreditStatusEnum.values()) {
            if (value.code.equals(code)) {
                return value.name;
            }
        }
        return null;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }
}
